import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../view/login.vue'
import test from '../view/test.vue'

Vue.use(VueRouter)

const routes = [

  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/test',
    name: 'test',
    component: test
  },
  {
    path: '/home',
    name: 'home',
    component: function () {
      return import('@/view/home')
    }
  }

]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/home') {
    if (window.sessionStorage.getItem('userinfo')) {
      //   console.log('ok')

      //   return next('/home')
    } else {
      console.log('ok')
      return next('/login')
    }
  }
  next()
})

export default router
